<?php
class RestaurantTDG_model extends CI_Model 
{
    private $TABLE = 'restaurant';

	public function __construct()
	{
		//$this->load->database();
	}

	public function findAll()
	{
		// return list of records matching criteria
		$query = $this->db->get( $this->TABLE  );
		return $query->result_array();
	}

	public function findById( $id )
	{
		// return a row matching criteria
		$query = $this->db->get_where( $this->TABLE, array('id' => $id) );
	}

	public function insert($name, $type, $address1, $address2, $city, $province, $postalCode, $country, $phoneNum)
	{
		$data = array(
					   'name' => $name,
					   'type' => $type,
					   'address1' => $address1,
					   'address2' => $address2,
					   'country' => $country,
					   'city' => $city,
					   'zip' => $postalCode,
					   'phone' => $phoneNum 
					 );

		$this->db->insert( $this->TABLE, $data); 

		// return id of the new entry
	}

	public function update($id, $version, $name, $type, $address1, $address2, $city, $province, $postalCode, $country, $phoneNum)
	{
		$data = array(
		               'name' => $name,
					   'type' => $type,
					   'address1' => $address1,
					   'address2' => $address2,
					   'country' => $country,
					   'city' => $city,
					   'zip' => $postalCode,
					   'phone' => $phoneNum 
		            );

		$this->db->where( array('id' => $id, 'version' => $version) );
		$this->db->update( $this->TABLE, $data); 

		// return id of the updated entry 

	}

	public function delete($id, $version)
	{
		$this->db->delete( $this->TABLE, array('id' => $id, 'version' => $version) ); 

		// return id of the deleted entry
		
	}

}